package com.zenika.zentracker.spring;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


public class HttpRequestInfoBean {

    private ServletRequestAttributes requestAttributes;
    
    private String sessionAttributeIdentifier;

    public HttpRequestInfoBean() {
        // TODO Modify as this clase may be different, and casting may not be possible
        requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    }        

    public Object getSessionInfo() {
        if (sessionAttributeIdentifier != null) {
            return requestAttributes.getRequest().getSession(false).getAttribute(sessionAttributeIdentifier);
        }

        return requestAttributes.getSessionId();
    }

    public String getRequestInfo() {
        return requestAttributes.getRequest().getRequestURI();
    }

    public void setSessionAttributeIdentifier(String sessionId) {
        this.sessionAttributeIdentifier = sessionId;
    }
    
}
